<?php
/**
 * Created by PhpStorm.
 * User: 图图
 * Date: 2021-5-11
 * Time: 9:12
 */
namespace app\common\model;

use think\Model;

/**
 * 会员售卡阶梯提成配置
 * @package app\admin\model
 */
class ViperCardConfig extends Model
{
    protected $name = 'qt_viper_card_config';
    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    /**
     * 售卡阶梯提成
     * @param $role
     * @param $totalMoney
     * @return int
     */
    public static function getCommission($role,$totalMoney,$number){
        $commission = 0;
        //计算金额提成
        $config = self::where("FIND_IN_SET(" . $role . ",role)")
            ->where('money_min','<',$totalMoney)
            ->where('money_max','>',$totalMoney)
            ->where('type','1')
            ->select();
        if(!empty($config)){
            foreach ($config as $key=>$value){
                $commission += ($totalMoney * $value['rate']) / 100;
            }
        }
        //计算次数提成
        $numberConfig = self::where("FIND_IN_SET(" . $role . ",role)")
            ->where('money_min','<',$number)
            ->where('money_max','>',$number)
            ->where('type','2')
            ->select();
        if(!empty($numberConfig)){
            foreach ($numberConfig as $key=>$value){
                $commission += ($totalMoney * $value['rate']) / 100;

            }
        }
        return $commission;
    }


}
